package com.delu.controller;


import com.alibaba.fastjson.JSONObject;
import com.delu.dto.RoundImgDTO;
import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.RoundImg;
import com.delu.service.RoundImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-12-17
 */
@Controller
@RequestMapping("/round-img")
@Api(value = "轮播图管理接口")
@RestController
public class RoundImgController {

    @Autowired
    private RoundImgService roundImgService;


    @GetMapping("roundList")
    @ApiOperation(value = "轮播图无参全部查询")
    public Result<List<RoundImgDTO>> roundImgList(){
        List<RoundImg> roundImgs = roundImgService.roundImgList();
        String s = JSONObject.toJSONString(roundImgs);
        List<RoundImgDTO> roundImgDTOS = JSONObject.parseArray(s, RoundImgDTO.class);
        return Result.response(ResultEnum.SUCCESS).setData(roundImgDTOS);
    }


    @PostMapping
    @ApiOperation(value = "轮播图增加")
    @ApiImplicitParam(name = "roundImg",value = "轮播图实体类",required = true,paramType = "body")
    public Result addRoundImg(@RequestBody RoundImg roundImg){
        Integer integer = roundImgService.addRoundImg(roundImg);
        return Result.response(ResultEnum.SUCCESS).setData(integer);
    }

    @PutMapping
    @ApiOperation(value = "轮播图有参")
    @ApiImplicitParam(name = "roundimageId",value = "基本数据类型",required = true,paramType = "query")
    public Result selectId(@RequestParam("roundimageId") Integer roundimageId){
        RoundImg roundImg = roundImgService.selectId(roundimageId);
        RoundImgDTO roundImgDTO = new RoundImgDTO();
        BeanUtils.copyProperties(roundImg,roundImgDTO);
        return Result.response(ResultEnum.SUCCESS).setData(roundImgDTO);
    }

    @DeleteMapping
    @ApiOperation(value = "轮播图删除")
    @ApiImplicitParam(name = "roundimageId",value = "基本数据类型",required = true,paramType = "query")
    public Result deleteId(@RequestParam("roundimageId") Integer roundimageId){
        Integer integer = roundImgService.deleteId(roundimageId);
        return Result.response(ResultEnum.SUCCESS).setData(integer);
    }

}
